<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Welcome to Reminder System</title>

<style type="text/css">

body {
 background-color: #fff;
 margin: 40px;
 font-family: Lucida Grande, Verdana, Sans-serif;
 font-size: 14px;
 color: #4F5155;
}

a {
 color: #003399;
 background-color: transparent;
 font-weight: normal;
}

h1 {
 color: #444;
 background-color: transparent;
 border-bottom: 1px solid #D0D0D0;
 font-size: 16px;
 font-weight: bold;
 margin: 24px 0 2px 0;
 padding: 5px 0 6px 0;
}

code {
 font-family: Monaco, Verdana, Sans-serif;
 font-size: 12px;
 background-color: #f9f9f9;
 border: 1px solid #D0D0D0;
 color: #002166;
 display: block;
 margin: 14px 0 14px 0;
 padding: 12px 10px 12px 10px;
}
div.ui-datepicker{
 font-size:12px;
}
</style>
<script>
function validate(){
	
	if(document.getElementById('username').value=="" ||
	document.getElementById('password').value=="" ||
	document.getElementById('email').value==""){
		document.getElementById('message').innerHTML = "Username, password and email are required.";
		return false;
	}	
}

function showdiv(divid){
	document.getElementById(divid).style.visibility='';
	if(divid == 'recurring'){
		document.getElementById('non-recurring').style.visibility='hidden';
	}
	else{
		document.getElementById('recurring').style.visibility='hidden';
	}
}

function new_task(){
	location.href="<?php echo site_url('welcome/new_task'); ?>";
}

</script>

<script type="text/javascript" src="<?php echo base_url();?>js/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>js/jquery-ui-1.8.14.custom.min.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>js/jquery-ui-timepicker-addon.js"></script>
<link href="<?php echo base_url();?>/css/ui-lightness/jquery-ui-1.8.14.custom.css" rel="stylesheet" type="text/css">
<link href="<?php echo base_url();?>/css/ui-lightness/jquery-ui-timepicker.css" rel="stylesheet" type="text/css">



</head>
<body>

<h1>Welcome to Reminder System!</h1>
<h2>My Task List</h2>
<div id="message" style="width:400px; background-color:#E0F0FF;">
	<?php
		echo $msg;
	?>
</div>		
<br/>
<input type="button" value="Create a new task" onclick="new_task()"/><br/><br/>
<?php
if(count($result['nr']) >0)
{
?>
My Non-Recurring Tasks<br><br>
<table border="1">
	<tr>
		<th>Task Name</th>
		<th>Date</th>
		<th>Time</th>
		<th>Notification</th>
		<th></th>
	</tr>
	<?php 
		foreach($result['nr'] as $nr){
			echo "<tr>
				<td>";
					echo $nr->task;
			echo "	</td>
				<td>";
					echo $nr->start_date;
			echo "	</td>
				<td>";
					echo $nr->reminder_time;
			echo "	</td>
				<td>";
					if($nr->is_email == 1)
						echo "email  ";
					if($nr->is_phone == 1)
						echo "phone ";
			
			$id = $nr->id;
			
			?>	</td>
				<td>
						
						<form name="NREditForm" action="<?php echo site_url('welcome/nr_edit'); ?>" method = "post">
							<input type="submit" value="Edit"/>
							<input type="hidden" name="id" value="<?php echo $id; ?>"/>
						</form>
						<form name="NRDeleteForm" action="<?php echo site_url('welcome/delete'); ?>" method = "post">
							<input type="submit" value="Delete"/>
							<input type="hidden" name="id" value="<?php echo $id; ?>"/>
						</form>
				</td>
			</tr><?php
		}
	?>

	</table>
<?php
}
else{
	echo "You have no Non-recurring tasks scheduled";
}
?>

<br/><br/><br/>
<?php
if(count($result['r']) >0)
{
?>
My Recurring Tasks<br><br>
	<table border="1">
		<tr>
			<th>Task Name</th>
			<th>Start Date</th>
			<th>End Date</th>
			<th>Time</th>
			<th>Days</th>
			<th>Notification</th>
			<th></th>
		</tr>
			<?php 
				foreach($result['r'] as $r){
					echo "<tr>
						<td>";
							echo $r->task;
					echo "</td>
						<td>";
							echo $r->start_date;
					echo "</td>
						<td>";
							echo $r->end_date;
					echo "</td>
						<td>";
							echo $r->reminder_time;
					echo "</td>
						<td>";
							$id = $r->id;
							$days_array = $result['days_array'];
							$resultset = $days_array[$id];
							
							foreach ($resultset->result() as $day_names) {
								echo $day_names->day_name . " ";
							}
					echo "</td>
							<td>";
							if($r->is_email == 1)
								echo "email  ";
							if($r->is_phone == 1)
								echo "phone ";
					?></td>
						<td>
							<form name="REditForm" action="<?php echo site_url('welcome/r_edit'); ?>" method = "post">
								<input type="submit" value="Edit"/>
								<input type="hidden" name="id" value="<?php echo $id; ?>"/>
							</form>
							<form name="RDeleteForm" action="<?php echo site_url('welcome/delete'); ?>" method = "post">
								<input type="submit" value="Delete"/>
								<input type="hidden" name="id" value="<?php echo $id; ?>"/>
							</form>
						</td>
					</tr>
				<?php
				}
			?>
	</table>
<?php
}
else{
echo "You have no Recurring tasks scheduled";
}
?>
</body>
		
</html>